﻿package net.wangit.user.privilege;

import java.util.HashMap;
import java.util.Map;

import net.wangit.MapList;
import net.wangit.Row;
import net.wangit.util.Checker;


public class PrivilegeUtil {

	public PrivilegeUtil() {
	}

	public static String getPrivilegeString(String domain, String type,
			String resourceId, String id) {
		StringBuffer result = new StringBuffer(domain);
		result.append(",").append(type).append(",").append(resourceId).append(
				",").append(id);
		return result.toString();
	}

	public static Map getPrivileges(MapList list) {
		Map privileges = new HashMap();
		if (!Checker.isEmpty(list)) {
			for (int i = 0; i < list.size(); i++) {
				Row row = list.getRow(i);
				String domain = row.get("domain");
				String unitId = row.get("rid");
				String type = row.get("type");
				String id = row.get("pid");
				privileges.put(getPrivilegeString(domain, type, unitId, id),
						null);
			}

		}
		return privileges;
	}
}
